﻿using Ionic.Zip;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Admin.Infra
{
    public class ZipResult : ActionResult
    {
        private string _fileName;
        private string _folderName;
        private const string SolutionTempLocation = @"C:\CatNav\Google Code\Asp.net MVC MVC 4 Integration\Admin\Content\temp\";

        public ZipResult(string folder, string zipName)
        {
            this._folderName = folder;
            _fileName = zipName;
        }

        public override void ExecuteResult(ControllerContext context)
        {
            using (ZipFile zip = new ZipFile())
            {
                zip.AddDirectory(_folderName);
                context.HttpContext
                    .Response.ContentType = "application/zip";
                context.HttpContext
                    .Response.AppendHeader("content-disposition", "attachment; filename=" + _fileName);
                //zip.Save(context.HttpContext.Response.OutputStream);
                zip.Save(SolutionTempLocation);
                Directory.Delete(_folderName);
            }
        }
    }
}